<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="xbsj-labels" content="Earth示例">
    </meta>
    <title>强制光照</title>
    <!-- 0 引入js文件：XbsjEarth.js和vue.min.js -->
    <script src="../../XbsjEarth/XbsjEarth.js"></script>
    <script src="./scripts/vue.min.js"></script>
    <style>
        html,
        body {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        .box span {
            display: inline-block;
            margin-top: 10px;
        }

        .defultbtn {
            display: inline-block;
            text-align: center;
            min-width: 60px;
            height: 38px;
            padding: 0 10px;
            line-height: 38px;
            border-radius: 100px;
            border: 1px solid #C9C9C9;
            background-color: #FFF;
            color: #555;
            cursor: pointer;
        }

        .defultbtn:hover {
            background-color: #b3daf8;
        }

        .btnon {
            background-color: #1E9FFF;
            color: #fff;
            border: 1px solid #1E9FFF;
        }

        input {
            width: 222px;
        }

        .notClick {
            pointer-events: none;
        }

        .divnotClick {
            pointer-events: none;
        }

        .divnotClick input {
            background: gray;
            border: none;
            padding: 3px 2px;
        }
    </style>
</head>

<body>
    <div id="vueApp" style="width: 100%; height: 100%; background: grey; position: relative;">
        <earth-comp></earth-comp>
    </div>

    <script>
        // 1 创建Earth的vue组件
        var EarthComp = {
            template: `
                <div style="width: 100%; height: 100%"  @click="raise = false,reduce = false">
                    <div ref="earthContainer" style="width: 100%; height: 100%">
                    </div>
                    <div class="box" style="position: absolute; left: 18px; top: 18px; color: white; background: rgba(0, 0, 0, 0.6); padding: 20px; border-radius: 25px;min-width:200px; font-size:24px; font-family: 宋体;">
                            <div class="defultbtn" :class="{'btnon':enabled}" @click="enabled = !enabled">强制光照</div><br/>
                            <span :class="enabled ? '': 'notClick'" @click="useCameraPos = !useCameraPos" style="cursor: pointer;"><input :disabled="!enabled" class="poyline" type="checkbox" style="width: 14px; cursor: pointer;" v-model="useCameraPos">相机方向</span><br/>
                            <div :class="enabled && !useCameraPos ? '': 'divnotClick'">
                                <span>强制光照位置</span><br/>
                                <span>经度：</span><input type="text" v-model="position[0].toFixed(5)">。<br/>
                                <span>纬度：</span><input type="text" v-model="position[1].toFixed(5)">。<br/>
                                <span>高度：</span><input type="text" v-model="position[2].toFixed(2)">m<br/>
                            </div>
                        </div>
                </div>
            `,
            data() {
                return {
                    _earth: undefined, // 注意：Earth和Cesium的相关变量放在vue中，必须使用下划线作为前缀！
                    enabled: false,
                    useCameraPos: false,
                    position: [0, 0, 0]
                };
            },
            // 1.1 资源创建
            mounted() {
                // 1.1.1 创建地球
                var earth = new XE.Earth(this.$refs.earthContainer);

                // 1.1.2 场景配置
                earth.sceneTree.root = {
                    "title": "当前场景",
                    "isSelected": true,
                    "children": [{
                        "czmObject": {
                            "xbsjType": "Imagery",
                            "enabled": true,
                            "name": "谷歌影像",
                            "show": true,
                            "xbsjImageryProvider": {
                                "XbsjImageryProvider": {
                                    "url": "//www.google.cn/maps/vt?lyrs=s&x={x}&y={y}&z={z}",
                                }
                            }
                        }
                    }, {
                        "ref": 'feiji',
                        "czmObject": {
                            "xbsjType": "Model",
                            "url": "../assets/GroundVehicle/feiji.glb",
                            "minimumPixelSize": 128,
                            "maximumScale": 20000,
                            "xbsjPosition": [
                                1.9017068269255648,
                                0.5972351777920929,
                                0
                            ],
                            "xbsjRotation": [
                                0,
                                0,
                                0
                            ],
                        }
                    }
                    ]
                };

                // var tileset = earth.sceneTree.$refs.tileset.czmObject;
                var feiji = earth.sceneTree.$refs.feiji.czmObject;

                // 设置相机位置
                // earth.camera.position.toString()和earth.camera.toAllJSONStr()这两个方法可获取相机位置
                earth.camera.position = [1.9017167018243972, 0.5972349991163317, 78.96451131309746];
                earth.camera.rotation = [4.7002176917891525, -0.8323406127413717, 6.278551580309028];

                // 1.1.5 数据绑定
                this._enabledUnbind = XE.MVVM.bind(this, 'enabled', earth.effect.forceSunPos, 'enabled');
                this._positionUnbind = XE.MVVM.bindPosition(this, 'position', earth.effect.forceSunPos, 'position');
                this._useCameraPosUnbind = XE.MVVM.bind(this, 'useCameraPos', earth.effect.forceSunPos, 'useCameraPos');
                // this._widthUnbind = XE.MVVM.bind(this, 'width', heatMap1, 'width');
                // this._heightUnbind = XE.MVVM.bind(this, 'height', heatMap1, 'height');

                this._earth = earth;

                // only for Debug
                // window.tileset = tileset;
                window.feiji = feiji;
                window.earth = earth;
            },
            // 1.2 资源销毁
            beforeDestroy() {
                // vue程序销毁时，需要清理相关资源
                this._enabledUnbind = this._enabledUnbind && this._enabledUnbind();
                this._positionUnbind = this._positionUnbind && this._positionUnbind();
                this._useCameraPosUnbind = this._useCameraPosUnbind && this._useCameraPosUnbind();
                // this._widthUnbind = this._widthUnbind && this._widthUnbind();
                // this._heightUnbind = this._heightUnbind && this._heightUnbind();
                this._earth = this._earth && this._earth.destroy();
            },
        }

        // 2 创建vue程序
        // XE.ready()用来加载Cesium.js等相关资源
        XE.ready().then(() => {
            var app = new Vue({
                el: '#vueApp',
                components: {
                    EarthComp,
                },
            });
        });
    </script>
</body>

</html>